﻿using System.Linq;
using System.Data;
using LibBusinessLayer;
namespace Roles
{
    public class SecurityServices
    {
        private static DataTable dtUserPermiss;
        private static readonly BllUsersInRoles _clsFunctionPage = new BllUsersInRoles();
        public static bool HasPermisstionPage(string ModuleName, int GroupID, bool Is_Page)
        {
            if (ModuleName == "")
                return true;
            return false;
        }
        public static bool HasPermisstionBtnAdd(string UserId, bool Is_BtnAdd)
        {
            dtUserPermiss = _clsFunctionPage.GetUsersInRoles(string.Empty);
            if (dtUserPermiss != null && dtUserPermiss.Rows.Count > 0)
            {
                return dtUserPermiss.Rows.Cast<DataRow>().Any(drUserPermiss => drUserPermiss["UserName"].ToString() == UserId && (bool) drUserPermiss["btnAddNew"] == Is_BtnAdd);
            }
            return false;
        }
        public static bool HasPermisstionBtnEdit(string UserId, bool Is_BtnEdit)
        {
            dtUserPermiss = _clsFunctionPage.GetUsersInRoles(string.Empty);
            if (dtUserPermiss != null && dtUserPermiss.Rows.Count > 0)
            {
                return dtUserPermiss.Rows.Cast<DataRow>().Any(drUserPermiss => drUserPermiss["UserName"].ToString() == UserId && (bool) drUserPermiss["btnEdit"] == Is_BtnEdit);
            }
            return false;
        }
        public static bool HasPermisstioBtnDel(string UserId, bool Is_BtnDel)
        {
            dtUserPermiss = _clsFunctionPage.GetUsersInRoles(string.Empty);
            if (dtUserPermiss != null && dtUserPermiss.Rows.Count > 0)
            {
                return dtUserPermiss.Rows.Cast<DataRow>().Any(drUserPermiss => drUserPermiss["UserName"].ToString() == UserId && (bool)drUserPermiss["btnDel"] == Is_BtnDel);
            }
            return false;
        }
        public static bool HasPermisstioBtnLock(string UserId, bool Is_BtnLock)
        {
            dtUserPermiss = _clsFunctionPage.GetUsersInRoles(string.Empty);
            if (dtUserPermiss != null && dtUserPermiss.Rows.Count > 0)
            {
                return dtUserPermiss.Rows.Cast<DataRow>().Any(drUserPermiss => drUserPermiss["UserName"].ToString() == UserId && (bool)drUserPermiss["btnLock"] == Is_BtnLock);
            }
            return false;
        }
    }
}